home *** CD-ROM | disk | FTP | other *** search
/ Directorty Opus 5 - Magellan 2 / Opus 5 - Magellan 2.iso / Extras / DopusJPEG11 / Pic2Jpeg.dopus5 < prev    next >
Text File  |  1996-02-04  |  3KB  |  142 lines

  1. /* Pic TO JPEG COMPRESSOR v1.1 [04-fev-96] for Directory Opus 5
  2.    By Christophe NOWAK
  3.  
  4.    Need the JPEGVxBin Package with cjpeg and djpeg
  5.    ilbmtoppm needed for IFF Pictures.
  6.    pcxtoppm needed for PCX Pictures.
  7.  
  8.    TODO : Support of PhotoCD and other formats
  9.           localisation ?
  10. */
  11.  
  12. parse arg portname scaleopt tmpdir option .
  13.  
  14. options results
  15. if portname='' then
  16.   portname='DOPUS.1'
  17. address value portname                  
  18.  
  19. lister query source
  20. if rc>0 then do
  21.   dopus request '"Error - No source files" ok'
  22.   call end_script
  23. end
  24.  
  25. parse var result handle .
  26.  
  27. lister set handle busy on
  28.  
  29. lister query handle path
  30. if rc>0 then
  31.   call end_script
  32. chemin=result
  33.  
  34. lister query handle selfiles stem files.
  35.  
  36. if files.count=0 then do
  37.   dopus request '"Error - No source files" ok'
  38.   call end_script
  39. end
  40.  
  41. dopus getstring '"Enter Compression Quality" 3 "" Ok'
  42. comp_quality=RESULT
  43. if LENGTH(comp_quality)=3 then do
  44.     dopus request '"Error - Quality must be < 100" ok'
  45.     call end_script
  46. end
  47.  
  48. lister set handle progress files.count 'Compressing Pictures...'
  49. lister set handle title 'Compressing Pictures...'
  50. lister refresh handle full
  51.  
  52. do i=0 to files.count-1
  53.   lister query handle abort
  54.   if result then
  55.     call end_script
  56.  
  57.   lister set handle progress count i+1
  58.   lister set handle progress name files.i
  59.   lister query handle entry files.i stem fileinfo.
  60.  
  61.   workfile='"'chemin||fileinfo.name'"'
  62.   if tmpdir=''|tmpdir='""' then
  63.     tmpfile='"'chemin||fileinfo.name||.tmp'"'
  64.   else tmpfile='"'tmpdir||fileinfo.name||.tmp'"'
  65.  
  66.   ext=reverse(fileinfo.name)            
  67.   parse var ext ext '.'
  68.   ext=upper(reverse(ext))
  69.  
  70.   if ext='JPG'|ext='JPEG'|ext='JFIF' then do
  71.     destfile='"'chemin||fileinfo.name||.new'"'
  72.     if scaleopt='SCALE' then
  73.       call scalepic
  74.     else scale=''
  75.     address command 'djpeg 'scale' -outfile' tmpfile workfile 
  76.     call Compress_File
  77.   end
  78.  
  79.   if ext='GIF'|ext='TGA'|ext='TARGA'|ext='PPM'|ext='PBM' then do
  80.     call getfilename
  81.     destfile='"'chemin||truncfile||jpg'"'
  82.     address command 'cjpeg -optimize -quality' comp_quality option workfile '>'destfile
  83.   end
  84.  
  85.   if ext='IFF'|ext='ILBM' then do
  86.     call getfilename
  87.     destfile='"'chemin||truncfile||jpg'"'
  88.     address command 'ilbmtoppm' workfile '>'tmpfile
  89.     call Compress_File
  90.   end
  91.  
  92.   if ext='PCX' then do
  93.     call getfilename
  94.     destfile='"'chemin||truncfile||jpg'"'
  95.     address command 'pcxtoppm' workfile '>'tmpfile
  96.     call Compress_File
  97.   end
  98.  
  99.   lister select handle '"'fileinfo.name'"' off
  100.   lister refresh handle full
  101. end
  102.  
  103. /* Comment the 5 following lines if you never want to delete the old files */
  104. if files.count>0 then do
  105.   dopus request '"Delete old files ?" Ok|Cancel'
  106.   if RC>0 then
  107.     call deleteold
  108. end
  109.    
  110. call end_script
  111.  
  112. deleteold:
  113.   do i=0 to files.count-1
  114.     address command 'delete' '"'chemin||fileinfo.name'"'
  115.   end
  116.   return
  117.  
  118. scalepic:
  119.   dopus request '"Select Scale Factor" 2|4|8|16|32|64|128|256|None'
  120.   if rc=0 then
  121.     scale=''
  122.   else scale='-scale 1/'||2**rc
  123.   return
  124.  
  125. getfilename:
  126.   truncfile = SUBSTR(fileinfo.name,1,LENGTH(fileinfo.name)-LENGTH(ext))
  127.   return
  128.  
  129. Compress_File:
  130.   address command 'cjpeg -optimize -quality' comp_quality option tmpfile '>'destfile
  131.   address command 'delete' tmpfile
  132.   return
  133.  
  134. Error:
  135.   dopus request '"Error in command - Sorry" ok'
  136.  
  137. end_script:
  138.   lister set handle title
  139.   lister refresh handle full
  140.   lister set handle busy off
  141.   EXIT
  142.